package com.six.config;

import com.six.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created by zxd on 2022/2/23 15:33
 */
//springboot启动的时候检测我们有没有一个类实现了WebMvcConfigurer接口,向上转型,调用接口的方法注册拦截器
@Configuration
public class MyMvcConfigure implements WebMvcConfigurer {

    @Bean
    public LoginInterceptor loginInterceptor(){
       return new LoginInterceptor();
    }

    //配置拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/**").
                excludePathPatterns("/admin/login","/swagger-resources/**","/webjars/**","/v2/**","/swagger-ui.html/**");
    }
}
